package br.com.virtualsoluction.utilitarios;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;

public class Configuracao {

    private String banco;
    private String driver;
    private String host;
    private String porta;
    private String senha;
    private String sgdb;
    private String usuario;

    private Properties p;
    private File arq;

    public String getBanco() {
        return banco;
    }

    public void setBanco(String banco) {
        this.banco = banco;
    }

    public String getDriver() {
        return driver;
    }

    public void setDriver(String driver) {
        this.driver = driver;
    }

    public String getHost() {
        return host;
    }

    public void setHost(String host) {
        this.host = host;
    }

    public String getPorta() {
        return porta;
    }

    public void setPorta(String porta) {
        this.porta = porta;
    }

    public String getSenha() {
        return senha;
    }

    public void setSenha(String senha) {
        this.senha = senha;
    }

    public String getSgdb() {
        return sgdb;
    }

    public void setSgdb(String sgdb) {
        this.sgdb = sgdb;
    }

    public String getUsuario() {
        return usuario;
    }

    public void setUsuario(String usuario) {
        this.usuario = usuario;
    }

    public Configuracao(){
        this.p = new Properties();
        this.arq = new File("d:\\config.properties" );
        try {
            this.p.load(new FileInputStream(this.arq));
        } catch (IOException ex) {
            Logger.getLogger(Configuracao.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public void lerArquivo(){           
        this.banco = p.getProperty("banco");
        this.driver = p.getProperty("driver");
        this.host = p.getProperty("host");
        this.porta = p.getProperty("porta");
        this.senha = p.getProperty("senha");
        this.sgdb = p.getProperty("sgdb");
        this.usuario = p.getProperty("usuario");
    }

    public void salvarArquivo(){        
        this.p.setProperty("banco", this.banco);
        this.p.setProperty("driver", this.driver);
        this.p.setProperty("host", this.host);
        this.p.setProperty("porta", this.porta);
        this.p.setProperty("senha", this.senha);
        this.p.setProperty("sgdb", this.sgdb);
        this.p.setProperty("usuario", this.usuario);
        
        try {
            this.p.save(new FileOutputStream(this.arq), "Config");
        } catch (FileNotFoundException ex) {
            Logger.getLogger(Configuracao.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
